﻿namespace Tszy.Examples.FSM
{
    public class TestState
    {
        public static void Execute()
        {
            StateMachine _machine = new StateMachine();

            var locomotionGroup = new LocomotionGroup();
            locomotionGroup.AddState(new Idle());

            _machine.AddState(locomotionGroup);

            var battleGroup = new BattleGroup();

            _machine.AddState(battleGroup);

            _machine.Execute();
            _machine.TrySetState(3);
        }
    }

    public class LocomotionGroup : StateMachine
    {
        public override long Identity { get; set; } = 1;
        public override void OnEnter()
        {
            Console.WriteLine($"进入 LocomotionGroup");
            base.OnEnter();
        }

        public override void OnUpdate()
        {
            Console.WriteLine($"正在执行 LocomotionGroup");
            base.OnUpdate();
        }

        public override void OnExit()
        {
            Console.WriteLine($"退出 LocomotionGroup");
            base.OnExit();
        }
    }

    public class Idle : State
    {
        public override long Identity { get; set; } = 2;
        public override void OnEnter()
        {
            Console.WriteLine($"进入 Idle");
            base.OnEnter();

        }

        public override void OnUpdate()
        {
            Console.WriteLine($"正在执行 Idle");
            base.OnUpdate();
        }

        public override void OnExit()
        {
            base.OnExit();
            Console.WriteLine($"退出 Idle");
        }
    }

    public class BattleGroup : StateMachine
    {
        public override long Identity { get; set; } = 3;
        public override void OnEnter()
        {
            Console.WriteLine($"进入 BattleGroup");
            base.OnEnter();
        }

        public override void OnUpdate()
        {
            Console.WriteLine($"正在执行 BattleGroup");
            base.OnUpdate();
        }

        public override void OnExit()
        {
            base.OnExit();
            Console.WriteLine($"退出 BattleGroup");
        }
    }
}
